/**
 * Created by kevin on 2017/6/6.
 */






// var server = net.createServer();


// server.on('connection',function (socket) {
//     socket.setEncoding('utf8');
//     sockets.push(socket);
//     socket.setKeepAlive(true);
//     socket.on('close',function () {
//         var index = sockets.indexOf(socket);
//         sockets.splice(index,1);
//     })
// })

var io = require('socket.io').listen(8081);
io.set('log level', 1);
io.sockets.on('connection', function (socket) {
    // console.log('con : ' + socket);
    socket.on('disconnect', function () {
        console.log('discon : ' + socket);

    });
});

function socketServer() {

}

// socketServer.stop = function () {
//     io.close();
// }

socketServer.sendMessage = function (action,tag,message) {
    io.emit('data',{
        data:message,
        action : action,
        tag : tag
    });
}

socketServer.sendError = function (action,tag,error) {
    io.emit('data',{
        error:error,
        action : action,
        tag : tag
    });
}

module.exports = socketServer;


